<template>
	<view :style="{'--page-bg':pageBg}" class="template-about tn-safe-area-inset-bottom "
		style="float: left;width: 100%;min-height: 100%;">

		<!-- 头像用户信息 -->
		<view
			class="top_max_box user-info__container tn-flex tn-flex-direction-column tn-flex-col-center tn-flex-row-center ">
			<view class="tn-shadow-blur"
				style="background-image:url('/static/logo.png');width: 120rpx;height: 120rpx;background-size: cover;border-radius:20%;">
			</view>

			<view class="user-info__nick-name-bottom" style="margin-top: 20px;">记录美好生活</view>
		</view>

		<!-- 更多信息-->
		<view
			class="about-shadow tn-margin-top-xl tn-padding-top-sm tn-padding-bottom-sm tn-margin-left tn-margin-right css-theme"
			:class="[cueTheme]">
			<!-- <tn-list-cell :hover="true" :unlined="true" :radius="true" :fontSize="30" @click="copyUrl(itemList.website)"
				class="css-theme" :class="[cueTheme]">
				<view class="tn-flex tn-flex-col-center">
					<view class="tn-margin-left-sm tn-flex-1">官网</view>
					<view class="tn-margin-left-sm tn-color-gray ">{{itemList.website}}</view>
				</view>
			</tn-list-cell> -->
			<tn-list-cell :hover="true" :unlined="true" :radius="true" :fontSize="30" @click="copyUrl(itemList.mailbox)"
				class="css-theme" :class="[cueTheme]">
				<view class="tn-flex tn-flex-col-center">
					<view class="tn-margin-left-sm tn-flex-1">邮箱</view>
					<view class="tn-margin-left-sm tn-color-gray ">{{itemList.mailbox}}</view>
				</view>
			</tn-list-cell>
			<tn-list-cell :hover="true" :unlined="true" :radius="true" :fontSize="30" @click="copyUrl(itemList.qqGroup)"
				class="css-theme" :class="[cueTheme]">
				<view class="tn-flex tn-flex-col-center">
					<view class="tn-margin-left-sm tn-flex-1">QQ群</view>
					<view class="tn-margin-left-sm tn-color-gray">{{itemList.qqGroup}}</view>
				</view>
			</tn-list-cell>
			<tn-list-cell :hover="true" :unlined="true" :radius="true" :fontSize="30" @click="copyUrl(itemList.qqGroup)"
				class="css-theme" :class="[cueTheme]">
				<view class="tn-flex tn-flex-col-center">
					<view class="tn-margin-left-sm tn-flex-1">微信</view>
					<view class="tn-margin-left-sm tn-color-gray">{{itemList.website}}</view>
				</view>
			</tn-list-cell>
		</view>

		<!-- 更多信息-->
		<view
			class="about-shadow tn-margin-top-xl tn-padding-top-sm tn-padding-bottom-sm tn-margin-left tn-margin-right css-theme"
			:class="[cueTheme]">
			<tn-list-cell :hover="true" :unlined="true" :radius="true" :fontSize="30" class="css-theme"
				:class="[cueTheme]">
				<view class="tn-flex tn-flex-col-center">
					<view class="tn-margin-left-sm tn-flex-1">软件版本</view>
					<view class="tn-margin-left-sm tn-color-gray">{{version}}</view>
				</view>
			</tn-list-cell>
			<tn-list-cell :hover="true" :unlined="true" :radius="true" :fontSize="30" @click="agreement(1)"
				class="css-theme" :class="[cueTheme]">
				<view class="tn-flex tn-flex-col-center">
					<view class="tn-margin-left-sm tn-flex-1">用户协议</view>
					<view class="tn-margin-left-sm tn-color-gray tn-icon-right"></view>
				</view>
			</tn-list-cell>
			<tn-list-cell :hover="true" :unlined="true" :radius="true" :fontSize="30" @click="agreement(2)"
				class="css-theme" :class="[cueTheme]">
				<view class="tn-flex tn-flex-col-center">
					<view class="tn-margin-left-sm tn-flex-1">隐私政策</view>
					<view class="tn-margin-left-sm tn-color-gray tn-icon-right"></view>
				</view>
			</tn-list-cell>
		</view>
		<view style="text-align: center;position: fixed;bottom: 50px;" >
			<button :style="{'background-color':pageBg}" @click="getVersion()"
				style="width:240rpx;border-radius: 30px;color: #18B998;height: 44px;line-height: 44px;margin-left: 255rpx;font-size: 14px;">检查更新</button>
		</view>


		<view style="position: fixed;bottom: 20px;text-align: center;width: 100%;font-size: 12px;color: #ccc;">
			皖ICP备2021008180号-2A <br>
			©2024 合肥美美云信息技术有限公司版权所有
		</view>

		<tn-modal title="版本更新提示" content="当前版本不是最新!点击确定更新版本!" v-model="modal_show"  @click="sureClick"></tn-modal>
		
		
		<uni-popup ref="process" type="center">
				<view class="popup-content">
					<progress :percent="progress" border-radius="5"></progress>
				</view>
				<view style="text-align: center;color: #fff;padding: 10px;">
					{{ '下载中: ' +  progress + '%'}}
				</view>
		</uni-popup>

	</view>
</template>

<script>
	var _self
	export default {

		data() {
			return {
				modal_show:false,
				progress: 0,
				user: [],
				itemList: {
					gw: "",
					mail: "",
					qq: "",
					version: "",
					remark:""
				},
				downloadUrl:''
			}
		},
		onLoad(options) {
			_self = this;
			this.version = uni.getSystemInfoSync().appWgtVersion

		},
		onShow() {
			uni.getStorage({
				key: 'user',
				success: function(res) {
					if (res.data) {
						_self.user = res.data
						setTimeout(function() {
							_self.getList()
							_self.getCommonInfo()
						}, 200);
					}
				},
				fail: function(e) {
					uni.navigateTo({
						url: '../login/login'
					});
				}
			})

		},
		methods: {
			getCommonInfo() {
				var data = {
					userId: _self.user.id
				}
				this.$api.commonInfo(data).then((res) => {
					var resData = res;
					
					if (resData.code == "200") {
						_self.downloadUrl = resData.data[0].info1
					}
				})
			
			},
			copyUrl(value) {
				uni.setClipboardData({
					data: value,
					success() {
						uni.showToast({
							title: '已复制',
							icon: 'none'
						});
					}
				});
			},
			agreement(type) {
				uni.navigateTo({
					url: '/pages/me/agreement?type=' + type
				});
			},

			getList() {
				var data = {
					userId: _self.user.id
				}
				this.$api.listMeAbout(data).then((res) => {
					var resData = res;
					if (resData.code == "200") {
						_self.itemList = resData.data[0];
						console.log(_self.itemList)
					}
				})

			},
			
			
			getVersion(){
				var type = 1
				// if (uni.getSystemInfoSync().platform == 'ios') {
				// 	type = 11
				// }
				var data = {
					type: type
				}
				this.$api.listHabitIcon(data).then((res) => {
					var resData = res;
				
					if (resData.code == "200") {
						console.log(resData.data[0].name)
						_self.updateVersion(resData.data[0].name)
						
					}
				})
				
			},
			// 比较版本号
			compareVersion(v1, v2) {
				const arr1 = v1.split('.')
				const arr2 = v2.split('.')
				if (arr1.length === arr2.length) {
					for (let i = 0; i < arr1.length; i++) {
						let ver1 = parseInt(arr1[i] || '0')
						let ver2 = parseInt(arr2[i] || '0')
						if (ver1 > ver2) {
							return 1
						} else if (ver1 < ver2) {
							return -1
						}
					}
					return 0
				} else {
					this.$showMessage('版本号的长度不一致，请联系管理员解决')
					return 0
				}
			},
			
			dialogConfirm() {
				var downloadTask = uni.downloadFile({
					url: _self.downloadUrl,
					success: (res) => {
						this.$refs.process.close()
						this.progress = 0
						if (res.statusCode === 200) {
							uni.openDocument({
								filePath: res.tempFilePath,
								success() {}
							})
						}
					}
				})
				downloadTask.onProgressUpdate(res => {
					this.$refs.process.open()
					this.progress = res.progress
				})
			},
			
			
			sureClick(e){
				this.modal_show = false;
				if(e.index==1){
					this.dialogConfirm()
				}
				
			},
			updateVersion(webVersion) {
				const systemInfo = uni.getSystemInfoSync();
				// 应用程序版本号
				// #ifdef APP
				var version = systemInfo.appWgtVersion;
				const compare = this.compareVersion(version, webVersion)
				if (compare < 0) {
					if (uni.getSystemInfoSync().platform == 'ios') {
						uni.showToast({
							title: "检查到新版本",
							duration: 2000,
							icon: "none"
						});
					} else {
						this.modal_show = true;
					}
				} else {
					uni.showToast({
						title: "已是最新版本",
						duration: 2000,
						icon: "none"
					});
				}
				// #endif
			
			
			},
		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
		background-color: $page-bg !important;
		// display: flex;
		width: 100%;
	}

	.css-theme {
		@include text-color();
		@include base-background();
		@include border-color();
		@include shadow-color();
	}

	// @import '@/static/css/templatePage/custom_nav_bar.scss';
	.template-about {
		background-color: $page-bg;
		padding-bottom: 40rpx;
	}


	.top_max_box {
		padding-top: 40rpx;
	}

	/* 顶部背景图 end */

	/* 波浪*/
	@keyframes move_wave {
		0% {
			transform: translateX(0) translateZ(0) scaleY(1)
		}

		50% {
			transform: translateX(-25%) translateZ(0) scaleY(1)
		}

		100% {
			transform: translateX(-50%) translateZ(0) scaleY(1)
		}
	}

	.tnwave {
		overflow: hidden;
		position: absolute;
		z-index: 9999;
		height: 200rpx;
		left: 0;
		right: 0;
		top: 290rpx;
		bottom: auto;
	}

	.waveWrapperInner {
		position: absolute;
		width: 100%;
		overflow: hidden;
		height: 100%;
	}

	.wave {
		position: absolute;
		left: 0;
		width: 200%;
		height: 100%;
		background-repeat: repeat no-repeat;
		background-position: 0 bottom;
		transform-origin: center bottom;
	}

	.bgTop {
		opacity: 0.4;
	}

	.waveTop {
		background-size: 50% 45px;
	}

	.waveAnimation .waveTop {
		animation: move_wave 4s linear infinite;
	}

	.bgMiddle {
		opacity: 0.6;
	}

	.waveMiddle {
		background-size: 50% 40px;
	}

	.waveAnimation .waveMiddle {
		animation: move_wave 3.5s linear infinite;
	}

	.bgBottom {
		opacity: 0.95;
	}

	.waveBottom {
		background-size: 50% 35px;
	}

	.waveAnimation .waveBottom {
		animation: move_wave 2s linear infinite;
	}

	/* 波浪*/

	/* 页面 start*/
	.about-shadow {
		border-radius: 15rpx;
		box-shadow: 0rpx 0rpx 50rpx 0rpx rgba(0, 0, 0, 0.07);
	}

	.about {

		&__wrap {
			position: relative;
			z-index: 1;
			// margin: 20rpx 30rpx;
			margin-top: -330rpx;
		}
	}

	/* 页面 end*/

	/* 用户信息 start */
	.user-info {
		&__container {}

		&__avatar {
			width: 170rpx;
			height: 170rpx;
			border: 8rpx solid rgba(255, 255, 255, 0.05);
			border-radius: 50%;
			overflow: hidden;
			box-shadow: 0rpx 0rpx 80rpx 0rpx rgba(0, 0, 0, 0.15);
		}

		&__nick-name {
			margin-top: 26rpx;
			font-size: 36rpx;
			font-weight: 600;
			text-align: center;
		}
	}

	/* 用户信息 end */
	/* 图标容器1 start */
	.icon1 {
		&__item {
			// width: 30%;
			background-color: #FFFFFF;
			border-radius: 10rpx;
			padding: 30rpx;
			margin: 20rpx 10rpx;
			transform: scale(1);
			transition: transform 0.3s linear;
			transform-origin: center center;

			&--icon {
				width: 40rpx;
				height: 40rpx;
				font-size: 28rpx;
				border-radius: 50%;
				position: relative;
				z-index: 1;

				&::after {
					content: " ";
					position: absolute;
					z-index: -1;
					width: 100%;
					height: 100%;
					left: 0;
					bottom: 0;
					border-radius: inherit;
					opacity: 1;
					transform: scale(1, 1);
					background-size: 100% 100%;
					background-image: url(https://tnuiimage.tnkjapp.com/cool_bg_image/icon_bg.png);
				}
			}
		}
	}

	/* 图标容器1 end */

	/* 底部tabbar start*/
	.footerfixed {
		position: fixed;
		width: 100%;
		bottom: 0;
		z-index: 999;
		background-color: #FFFFFF;
		box-shadow: 0rpx 0rpx 30rpx 0rpx rgba(0, 0, 0, 0.07);
	}

	.tabbar {
		display: flex;
		align-items: center;
		min-height: 110rpx;
		justify-content: space-between;
		padding: 0;
		height: calc(110rpx + env(safe-area-inset-bottom) / 2);
		padding-bottom: calc(env(safe-area-inset-bottom) / 2);
	}

	.tabbar .action {
		font-size: 22rpx;
		position: relative;
		flex: 1;
		text-align: center;
		padding: 0;
		display: block;
		height: auto;
		line-height: 1;
		margin: 0;
		overflow: initial;
	}

	.tabbar .action .bar-icon {
		width: 100rpx;
		position: relative;
		display: block;
		height: auto;
		margin: 0 auto 10rpx;
		text-align: center;
		font-size: 42rpx;
	}

	.tabbar .action .bar-icon image {
		width: 50rpx;
		height: 50rpx;
		display: inline-block;
	}

	.user-info__nick-name-top {
		font-weight: bold;
		margin-top: 20rpx;
		font-size: 18px;

	}

	.user-info__nick-name-bottom {
		margin-top: 20rpx;
		color: #A8A8A8;
		font-size: 14px;
		letter-spacing: 10px;
	}
</style>